<template>
  <el-dialog width="30%" @close="colseDialog" :close-on-click-modal="false">
    <el-form :model="form">
      <div class="container">
        <div class="panda">
          <div class="ear left"></div>
          <div class="ear right"></div>
          <div class="face">
            <div class="eye-shadow left"></div>
            <div class="eye-white left">
              <div class="eye-ball"></div>
            </div>
            <div class="eye-shadow right"></div>
            <div class="eye-white right">
              <div class="eye-ball"></div>
            </div>
            <div class="nose"></div>
            <div class="mouth"></div>
          </div>
          <div class="body"></div>
          <div class="foot left">
            <div class="sole"></div>
          </div>
          <div class="foot right">
            <div class="sole"></div>
          </div>
        </div>
        <div class="login-box">
          <div class="hand left"></div>
          <div class="hand right"></div>
          <h1>用户登录</h1>
          <div class="ipt-box">
            <input type="text" required v-model="form.name" />
            <label>用户名</label>
          </div>
          <div class="ipt-box">
            <input type="password" id="password" v-model="form.pw" autocomplete="off" required />
            <label>密码</label>
          </div>
          <el-button type="primary" plain @click="handlelogin">登录</el-button>
        </div>
      </div>
    </el-form>
  </el-dialog>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
const store = useStore()
const router = useRouter()
/* 获取鼠标移动的位置，让 eye-ball眼球跟随鼠标移动*/
const getMousePosition = (e) => {
  // 获取屏幕宽度
  const screenWidth = document.body.clientWidth / 10
  // 获取屏幕高度
  const screenHeight = document.body.clientHeight / 18
  // 获取鼠标X坐标
  const mouseX = e.clientX / screenWidth
  // 获取鼠标Y坐标
  const mouseY = e.clientY / screenHeight
  // 返回鼠标坐标
  return {
    x: mouseX,
    y: mouseY
  }
}
const handleMouseMove = (e) => {
  const { x, y } = getMousePosition(e)
  const eyeBall = document.querySelectorAll('.eye-ball')
  eyeBall.forEach((item) => {
    item.style.left = `${x}px`
    item.style.top = `${y}px`
  })
}
onMounted(() => {
  window.document.addEventListener('mousemove', handleMouseMove)
})

const form = ref({
  name: 'zoker',
  pw: 'zoker'
})
const colseDialog = () => {
  store.commit('app/setDialogVisible')
}
const handlelogin = () => {
  console.log(form.value)
  // const res = await loginApi(form.value)
  // console.log(res)
  store.dispatch('app/login', form.value)

  // router.push('/')
}
</script>
<style>
.el-overlay {
  background-color: rgba(0, 0, 0, 0.5);
}
.el-dialog {
  background: transparent;
  box-shadow: none;
}
.el-dialog .el-icon svg {
  color: #f1f1f1;
}
.el-dialog .el-icon svg:hover {
  color: #1e80ff;
}
.el-dialog__headerbtn .el-dialog__close {
  font-size: 36px;
}
</style>
<style lang="scss" scoped>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
}
/* 开始画熊猫 */
.panda {
  /* 相对定位 */
  position: relative;

  width: 200px;
}
/* 脸部 */
.face {
  width: 200px;
  height: 200px;
  background-color: #fff;
  border-radius: 100%;
  box-shadow: 0 10px 15px rgba(0, 0, 0, 0.15);
  position: relative;
  z-index: 1;
}
/* 耳朵 */
.ear {
  width: 70px;
  height: 70px;
  background-color: #000;
  border-radius: 100%;
  position: absolute;
  top: -10px;
}
.ear.right {
  right: 0;
}
/* 黑眼圈 */
.eye-shadow {
  width: 50px;
  height: 80px;
  background-color: #000;
  border-radius: 50%;
  /* 绝对定位 */
  position: absolute;
  top: 40px;
}
.eye-shadow.left {
  transform: rotate(45deg);
  left: 30px;
}
.eye-shadow.right {
  transform: rotate(-45deg);
  right: 30px;
}
/* 眼白 */
.eye-white {
  width: 30px;
  height: 30px;
  background-color: #fff;
  border-radius: 100%;
  position: absolute;
  top: 68px;
}
.eye-white.left {
  left: 38px;
}
.eye-white.right {
  right: 38px;
}
/* 眼球 */
.eye-ball {
  width: 20px;
  height: 20px;
  background-color: #000;
  border-radius: 100%;
  position: absolute;
  left: 5px;
  top: 5px;
}
/* 鼻子 */
.nose {
  width: 35px;
  height: 20px;
  background-color: #000;
  position: absolute;
  left: 0;
  right: 0;
  margin: auto;
  bottom: 65px;
  border-radius: 42px 42px 60px 60px / 30px 30px 60px 60px;
}
/* 嘴巴 */
.mouth {
  width: 68px;
  height: 25px;
  border-bottom: 7px solid #000;
  border-radius: 50%;
  position: absolute;
  left: 0;
  right: 0;
  margin: auto;
  bottom: 35px;
}
/* 身体 */
.body {
  width: 250px;
  height: 280px;
  background-color: #fff;
  position: relative;
  left: -25px;
  top: -10px;
  border-radius: 100px 100px 100px 100px / 126px 126px 96px 96px;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.3);
}
/* 脚 */
.foot {
  width: 82px;
  height: 120px;
  background-color: #000;
  position: absolute;
  bottom: 8px;
  z-index: 3;
  border-radius: 40px 40px 35px 40px / 26px 26px 63px 63px;
  box-shadow: 0 5px 5px rgba(0, 0, 0, 0.2);
}
.foot.left {
  left: -80px;
}
.foot.right {
  right: -80px;
  transform: rotateY(180deg);
}
/* 脚掌-大椭圆 */
.foot::after {
  content: '';
  width: 55px;
  height: 65px;
  background-color: #222;
  position: absolute;
  border-radius: 50%;
  left: 0;
  right: 0;
  margin: auto;
  bottom: 10px;
}
/* 脚掌-三个小椭圆 */
.foot .sole,
.foot .sole::before,
.foot .sole::after {
  width: 20px;
  height: 30px;
  background-color: #222;
  position: absolute;
  border-radius: 50%;
  left: 0;
  right: 0;
  margin: auto;
  top: 8px;
}
.foot .sole::before {
  content: '';
  left: -50px;
}
.foot .sole::after {
  content: '';
  left: 25px;
}
/* 手 */
.hand,
.hand::before,
.hand::after {
  width: 40px;
  height: 30px;
  background-color: #000;
  border-radius: 50px;
  position: absolute;
  top: 70px;
  left: -20px;
}
.hand::before {
  content: '';
  top: 16px;
  left: 0;
}
.hand::after {
  content: '';
  top: 32px;
  left: 0;
}
.hand.right {
  right: -20px;
  left: auto;
}
/* 登录框 */
.login-box {
  width: 400px;
  height: 300px;
  background-color: #fff;
  border-radius: 3px;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -110px);
  z-index: 2;
  /* 弹性布局 居中 垂直排列 */
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  /* 设置过渡 */
  transition: all 0.3s ease-in-out;
}
h1 {
  color: $jjColor;
  font-weight: normal;
  margin-bottom: 5px;
}
.ipt-box {
  width: 80%;
  margin-top: 25px;
  position: relative;
}
.ipt-box input {
  width: 100%;
  height: 35px;
  border: none;
  border-bottom: 1px solid #bbb;
  text-indent: 5px;
  outline: none;
  transition: 0.3s;
}
.ipt-box label {
  position: absolute;
  left: 5px;
  top: 5px;
  font-size: 14px;
  color: #888;
  transition: 0.3s;
  pointer-events: none;
}
/* 输入框选中或有值时输入框的样式 */
.ipt-box input:focus,
.ipt-box input:valid {
  border-color: $jjColor;
  box-shadow: 0 1px $jjColor;
}
/* 输入框选中或有值时label的样式 */
.ipt-box input:focus ~ label,
.ipt-box input:valid ~ label {
  color: $jjColor;
  font-size: 12px;
  transform: translateY(-15px);
}
button {
  width: 150px;
  height: 40px;
  background-color: $jjColor;
  border: none;
  border-radius: 3px;
  margin-top: 30px;
  color: #fff;
  letter-spacing: 10px;
  text-indent: 10px;
  cursor: pointer;
  transition: 0.3s;
}
button:hover {
  letter-spacing: 25px;
  text-indent: 25px;
  background-color: $jjColor;
}
/* 登录框向上举 */
.login-box:focus-within {
  transform: translate(-50%, -180px);
}
</style>
